home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / What's New? / Development Kits / Apple Game Sprockets DR1 / Examples / GlyphaIII / G3Interface.c < prev    next >
Encoding:
Text File  |  1996-04-24  |  19.2 KB  |  631 lines  |  [TEXT/MPCC]

  1.  
  2. //============================================================================
  3. //----------------------------------------------------------------------------
  4. //                                    Interface.c
  5. //----------------------------------------------------------------------------
  6. //============================================================================
  7.  
  8. // I put all interface related code in here.  Interface would include event…
  9. // handling, menus, dialog boxes, etc.  All the user interaction that takes…
  10. // place before and after an actual game is in play.
  11.  
  12. #include "G3Externs.h"
  13. #include <Sound.h>
  14.  
  15.  
  16. #define kAppleMenuID        128
  17. #define iAbout                1
  18. #define kGameMenuID            129
  19. #define iNewGame            1
  20. #define iPauseGame            2
  21. #define iEndGame            3
  22. #define iQuit                5
  23. #define kOptionsMenuID        130
  24. #define iSettings            1
  25. #define iHelp                2
  26. #define iHighScores            3
  27. #define kAboutPictID        132
  28.  
  29.  
  30. void DoAppleMenu (short);
  31. void DoGameMenu (short);
  32. void DoOptionsMenu (short);
  33. void UpdateMainWindow (void);
  34. void HandleMouseEvent (EventRecord *);
  35. void HandleKeyEvent (EventRecord *);
  36. void HandleUpdateEvent (EventRecord *);
  37. void HandleOSEvent (EventRecord *);
  38. void HandleHighLevelEvent (EventRecord *);
  39. void DoAbout (void);
  40. void DoGameSettings (void);
  41.  
  42.  
  43. Rect        mainWindowRect;
  44.  
  45. // when generating PowerPC code for the Apple Game Sprockets, the mainWindow
  46. // isn't really a WindowPtr, its a CGrafPtr.  Don't try to use it with the
  47. // Window Manager!
  48. WindowPtr    mainWindow;
  49.  
  50. MenuHandle    appleMenu, gameMenu, optionsMenu;
  51. Boolean        switchedOut, quitting, canPlay, openTheScores;
  52.  
  53. extern    prefsInfo    thePrefs;
  54. extern    Rect        backSrcRect, workSrcRect;
  55. extern    CGrafPtr    backSrcMap, workSrcMap;
  56. extern    Boolean        pausing, playing, helpOpen, scoresOpen;
  57.  
  58.  
  59. //==============================================================  Functions
  60. //--------------------------------------------------------------  MenusReflectMode
  61.  
  62. // Depending on whether a game is in progress (paused) or not, I want…
  63. // menu items grayed out in one case and not grayed out in the other.
  64. // This function, when called, displays the menus correctly depending…
  65. // on the mode we're in (playing or not playing, pausing or not).
  66.  
  67. void MenusReflectMode (void)
  68. {
  69.     if (playing)                                // If a game is in progress…
  70.     {
  71.         DisableItem(gameMenu, iNewGame);        // Cannot begin another New Game.
  72.         EnableItem(gameMenu, iPauseGame);        // Can Pause Game.
  73.         if (pausing)                            // If we are paused…
  74.             SetItem(gameMenu, iPauseGame, 
  75.                     "\pResume Game");            // Rename item "Resume Game".
  76.         else                                    // If we are not paused…
  77.             SetItem(gameMenu, iPauseGame, 
  78.                     "\pPause Game");            // Rename item "Pause Game".
  79.         EnableItem(gameMenu, iEndGame);            // Can End Game.
  80.         DisableItem(optionsMenu, 0);            // Cannot change game settings.
  81.     }
  82.     else                                        // Else, if Glypha is idle…
  83.     {
  84.         EnableItem(gameMenu, iNewGame);            // Can begin a New Game.
  85.         DisableItem(gameMenu, iPauseGame);        // Cannot Pause Game.
  86.         SetItem(gameMenu, iPauseGame, 
  87.                 "\pPause Game");                // Rename item "Pause Game".
  88.         DisableItem(gameMenu, iEndGame);        // Cannot End Game.
  89.         EnableItem(optionsMenu, 0);                // Can change game settings.
  90.     }
  91. }
  92.  
  93. //--------------------------------------------------------------  DoAppleMenu
  94.  
  95. // This function takes care of handling the Apple menu (Desk Assecories and the…
  96. // About box).
  97.  
  98. void DoAppleMenu (short theItem)
  99. {
  100.     Str255        daName;
  101.     GrafPtr        wasPort;
  102.     short        daNumber;
  103.     
  104.     switch (theItem)                            // Depending on the item selected…
  105.     {
  106.         case iAbout:                            // If the About item was selected…
  107.         if ((scoresOpen) || (helpOpen))            // If high scores or help screens up…
  108.         {
  109.             CloseWall();                        // hide them.
  110.             scoresOpen = FALSE;                    // High scores no longer open.
  111.             helpOpen = FALSE;                    // Help screen is no longer open.
  112.                                                 // Uncheck help & high scores menu items.
  113.             CheckItem(optionsMenu, iHelp, helpOpen);
  114.             CheckItem(optionsMenu, iHighScores, scoresOpen);
  115.         }
  116.         DoAbout();                                // Bring up the About dialog.
  117.         break;
  118.         
  119.         default:                                // If any other item was selected (DA)…
  120.         GetItem(appleMenu, theItem, daName);    // Get the name of the item selected.
  121.         GetPort(&wasPort);                        // Remember our port.
  122.         daNumber = OpenDeskAcc(daName);            // Launch the Desk Accesory.
  123.         SetPort((GrafPtr)wasPort);                // When we return, restore port.
  124.         break;
  125.     }
  126. }
  127.  
  128. //--------------------------------------------------------------  DoGameMenu
  129.  
  130. // This function handles a users interaction with the Game menu.  Quitting…
  131. // Glypha, starting a new game, resuming a paused game are handled here.
  132.  
  133. void DoGameMenu (short theItem)
  134. {
  135.     switch (theItem)                        // Depending on menu item selected…
  136.     {
  137.         case iNewGame:                        // If user selected New Game item…
  138.         if ((scoresOpen) || (helpOpen))        // If high scores or help screen is up,…
  139.         {                                    // close them first.
  140.             CloseWall();
  141.             scoresOpen = FALSE;
  142.             helpOpen = FALSE;
  143.             CheckItem(optionsMenu, iHelp, helpOpen);
  144.             CheckItem(optionsMenu, iHighScores, scoresOpen);
  145.         }
  146.         InitNewGame();                        // Initialize variables for a new game.
  147.         MenusReflectMode();                    // Properly gray out the right menu items.
  148.         break;
  149.         
  150.         case iPauseGame:                    // If user selected Pause Game item…
  151.         if (pausing)                        // If we are paused, resume playing.
  152.         {
  153.             pausing = FALSE;                // Turn off pausing flag.
  154.             DumpBackToWorkMap();            // Restore off screen just in case.
  155.         }                                    // Actually pausing a game (not resuming)…
  156.         break;                                // is not really handled here.  It's handled…
  157.                                             // directly within the main game loop.
  158.                                             
  159.         case iEndGame:                        // Ending a game in progress isn't really…
  160.         break;                                // handled here - this is a dummy item.
  161.                                             // Ending a game is handled within the main…
  162.                                             // game loop by looking for the 'command'…
  163.                                             // and 'E' key explicitly.
  164.         
  165.         case iQuit:                            // If user selected Quit item…
  166.         quitting = TRUE;                    // Set quitting flag to TRUE.
  167.         break;
  168.     }
  169. }
  170.  
  171. //--------------------------------------------------------------  DoOptionsMenu
  172.  
  173. // This function handles the Options menu.  Options include game settings,…
  174. // displaying the high scores, and bringing up the Help screen.
  175.  
  176. void DoOptionsMenu (short theItem)
  177. {
  178.     switch (theItem)                    // Depending on which item the user selected…
  179.     {
  180.         case iSettings:                    // If user selected Game Settings item…
  181.         if ((scoresOpen) || (helpOpen))    // Close high scores or help screen.
  182.         {
  183.             CloseWall();
  184.             scoresOpen = FALSE;
  185.             helpOpen = FALSE;
  186.             CheckItem(optionsMenu, iHelp, helpOpen);
  187.             CheckItem(optionsMenu, iHighScores, scoresOpen);
  188.         }
  189.         DoGameSettings();                // Bring up game settings dialog.
  190.         break;
  191.         
  192.         case iHelp:                        // If user selected Help item…
  193.         if (helpOpen)                    // If Help open, close it.
  194.         {
  195.             CloseWall();
  196.             helpOpen = FALSE;
  197.         }
  198.         else                            // Else, if Help is not open - open it.
  199.         {
  200.             if (scoresOpen)                // If the High Scores are up though,…
  201.             {
  202.                 CloseWall();            // Close them first.
  203.                 scoresOpen = FALSE;
  204.                 CheckItem(optionsMenu, iHighScores, scoresOpen);
  205.             }
  206.             OpenHelp();                    // Now open the Help screen.
  207.         }
  208.         CheckItem(optionsMenu, iHelp, helpOpen);
  209.         break;
  210.         
  211.         case iHighScores:                // If user selected High Scores…
  212.         if (scoresOpen)                    // If the High Scores are up, close them.
  213.         {
  214.             CloseWall();
  215.             scoresOpen = FALSE;
  216.         }
  217.         else                            // If the High Scores are not up…
  218.         {
  219.             if (helpOpen)                // First see if Help is open.
  220.             {
  221.                 CloseWall();            // And close the Help screen.
  222.                 helpOpen = FALSE;
  223.                 CheckItem(optionsMenu, iHelp, helpOpen);
  224.             }
  225.             OpenHighScores();            // Now open the High Scores.
  226.         }
  227.         CheckItem(optionsMenu, iHighScores, scoresOpen);
  228.         break;
  229.     }
  230. }
  231.  
  232. //--------------------------------------------------------------  DoMenuChoice
  233.  
  234. // This is the main menu-handling function.  It examines which menu was selected…
  235. // by the user and passes on to the appropriate function, the item within that…
  236. // menu that was selected.
  237.  
  238. void DoMenuChoice (long menuChoice)
  239. {
  240.     short        theMenu, theItem;
  241.     
  242.     if (menuChoice == 0)            // A little error checking.
  243.         return;
  244.     
  245.     theMenu = HiWord(menuChoice);    // Extract which menu was selected.
  246.     theItem = LoWord(menuChoice);    // Extract which item it was that was selected.
  247.     
  248.     switch (theMenu)                // Now, depending upon which menu was selected…
  249.     {
  250.         case kAppleMenuID:            // If the Apple menu selected…
  251.         DoAppleMenu(theItem);        // Call the function that handles the Apple menu.
  252.         break;
  253.         
  254.         case kGameMenuID:            // If the Game menu selected…
  255.         DoGameMenu(theItem);        // Call the function that handles the Game menu.
  256.         break;
  257.         
  258.         case kOptionsMenuID:        // If the Options menu selected…
  259.         DoOptionsMenu(theItem);        // Call the function that handles the Options menu.
  260.         break;
  261.     }
  262.     
  263.     HiliteMenu(0);                    // "De-invert" menu.
  264. }
  265.  
  266. //--------------------------------------------------------------  UpdateMainWindow
  267.  
  268. // This is a simple function that simply copies the contents from the…
  269. // background offscreen pixmap to the main screen.  It is primarily…
  270. // called in response to an update event, but could be called any time…
  271. // when I want to force the screen to be redrawn.
  272.  
  273. void UpdateMainWindow (void)
  274. {
  275. #if GENERATINGPOWERPC
  276.  
  277.     OSStatus theError;
  278.     
  279.     theError = GetDisplayBackBuffer( gTheDisplay, &workSrcMap );
  280.     if( theError )
  281.     {
  282.         DisposeDisplay( gTheDisplay );
  283.         RedAlert("\pUnable to get back buffer");
  284.     }
  285.  
  286.     CopyBits(&((GrafPtr)backSrcMap)->portBits, 
  287.             &(((GrafPtr)workSrcMap)->portBits), 
  288.             &mainWindowRect, &mainWindowRect, 
  289.             srcCopy, 0L);
  290.  
  291.     SwapDisplayBuffers( gTheDisplay, NULL, 0 );
  292.     
  293. #else
  294.  
  295.     CopyBits(&((GrafPtr)backSrcMap)->portBits, 
  296.             &(((GrafPtr)mainWindow)->portBits), 
  297.             &mainWindowRect, &mainWindowRect, 
  298.             srcCopy, 0L);
  299.  
  300. #endif
  301. }
  302.  
  303. //--------------------------------------------------------------  HandleMouseEvent
  304.  
  305. // Mouse clicks come here.  This is standard event-handling drivel.  No different 
  306. // from any other standard Mac program (game or otherwise).
  307.  
  308. void HandleMouseEvent (EventRecord *theEvent)
  309. {
  310.     WindowPtr    whichWindow;
  311.     Point        localPoint;
  312.     long        menuChoice;
  313.     short        thePart;
  314.                                                 // Determine window and where in window.
  315.     thePart = FindWindow(theEvent->where, &whichWindow);
  316.     
  317.     switch (thePart)                            // Depending on where mouse was clicked…
  318.     {
  319.         case inSysWindow:                        // In a Desk Accesory.
  320.         SystemClick(theEvent, whichWindow);        // (Is this stuff obsolete yet?)
  321.         break;
  322.         
  323.         case inMenuBar:                            // Selected a menu item.
  324.         menuChoice = MenuSelect(theEvent->where);
  325.         if (canPlay)                            // Call menu handling routine.
  326.             DoMenuChoice(menuChoice);
  327.         break;
  328.         
  329.         case inDrag:                            // Like the lazy bastard I am…
  330.         case inGoAway:                            // I'll just ignore these.
  331.         case inGrow:                            // But, hey, the window isn't…
  332.         case inZoomIn:                            // movable or growable!
  333.         case inZoomOut:
  334.         break;
  335.         
  336.         case inContent:                            // Click in the window itself.
  337.         FlashObelisks(TRUE);                    // Do lightning animation.
  338.         LogNextTick(3);                            // Lightning will hit cursor location.
  339.         localPoint = theEvent->where;
  340.         GlobalToLocal(&localPoint);
  341.         GenerateLightning(localPoint.h, localPoint.v);
  342.         StrikeLightning();
  343.         WaitForNextTick();
  344.         StrikeLightning();
  345.         LogNextTick(2);
  346.         WaitForNextTick();
  347.         PlayExternalSound(kLightningSound, kLightningPriority);
  348.         LogNextTick(3);
  349.         GenerateLightning(localPoint.h, localPoint.v);
  350.         StrikeLightning();
  351.         WaitForNextTick();
  352.         StrikeLightning();
  353.         LogNextTick(2);
  354.         WaitForNextTick();
  355.         LogNextTick(3);
  356.         GenerateLightning(localPoint.h, localPoint.v);
  357.         StrikeLightning();
  358.         WaitForNextTick();
  359.         StrikeLightning();
  360.         LogNextTick(2);
  361.         WaitForNextTick();
  362.         PlayExternalSound(kLightningSound, kLightningPriority);
  363.         LogNextTick(3);
  364.         GenerateLightning(localPoint.h, localPoint.v);
  365.         StrikeLightning();
  366.         WaitForNextTick();
  367.         StrikeLightning();
  368.         LogNextTick(2);
  369.         WaitForNextTick();
  370.         FlashObelisks(FALSE);
  371.         break;
  372.     }
  373. }
  374.  
  375. //--------------------------------------------------------------  HandleKeyEvent
  376.  
  377. // More standard issue.  This function handles any keystrokes when no game is
  378. // in session.  Command-key strokes handled here too.
  379.  
  380. void HandleKeyEvent (EventRecord *theEvent)
  381. {
  382.     char        theChar;
  383.     Boolean        commandDown;
  384.     
  385.     theChar = theEvent->message & charCodeMask;                // Extract key hit.
  386.     commandDown = ((theEvent->modifiers & cmdKey) != 0);    // See if command key down.
  387.     
  388.     if (commandDown)                                // If command key down, call menu…
  389.     {                                                // handling routine.
  390.         if (canPlay)
  391.             DoMenuChoice(MenuKey(theChar));
  392.     }
  393.     else
  394.     {
  395.         if (helpOpen)                                // Handle special keys if the help…
  396.         {                                            // screen is up.
  397.             if (theChar == kUpArrowKeyASCII)        // Up arrow key scrolls help down.
  398.             {
  399.                 if (theEvent->what == autoKey)
  400.                     ScrollHelp(-3);
  401.                 else
  402.                     ScrollHelp(-1);
  403.             }
  404.             else if (theChar == kDownArrowKeyASCII)    // Down arrow key scrolls help up.
  405.             {
  406.                 if (theEvent->what == autoKey)
  407.                     ScrollHelp(3);
  408.                 else
  409.                     ScrollHelp(1);
  410.             }
  411.             else if (theChar == kPageDownKeyASCII)    // Handle page down for help screen.
  412.             {
  413.                 ScrollHelp(199);
  414.             }
  415.             else if (theChar == kPageUpKeyASCII)    // Handle page up for help.
  416.             {
  417.                 ScrollHelp(-199);
  418.             }
  419.             else if ((theChar == kHelpKeyASCII) && (!playing))
  420.             {                                        // Hitting Help key closes help…
  421.                 CloseWall();                        // (if it's already open).
  422.                 helpOpen = FALSE;
  423.                 CheckItem(optionsMenu, iHelp, helpOpen);
  424.             }
  425.         }
  426.         else if ((theChar == kHelpKeyASCII) && (!playing))
  427.         {                                            // Else, if help not open and Help…
  428.             if (scoresOpen)                            // key is hit, open Help.
  429.             {                                        // Close high scores if open.
  430.                 CloseWall();
  431.                 scoresOpen = FALSE;
  432.                 CheckItem(optionsMenu, iHighScores, scoresOpen);
  433.             }
  434.             OpenHelp();                                // Open help.
  435.             CheckItem(optionsMenu, iHelp, helpOpen);
  436.         }
  437.     }
  438. }
  439.  
  440. //--------------------------------------------------------------  HandleUpdateEvent
  441.  
  442. // This function handles update events.  Standard event-handling stuff.
  443.  
  444. void HandleUpdateEvent (EventRecord *theEvent)
  445. {    
  446. #if !GENERATINGPOWERPC
  447.     if ((WindowPtr)theEvent->message == mainWindow)
  448.     {
  449.         SetPort((GrafPtr)mainWindow);        // Don't forget this line, BTW.
  450.         BeginUpdate((GrafPtr)mainWindow);    // I did once and it took me…
  451.         UpdateMainWindow();                    // ages to track down that bug.
  452.         EndUpdate((GrafPtr)mainWindow);        // Well, it took me a week I think.
  453.         canPlay = TRUE;
  454.     }
  455. #endif
  456. }
  457.  
  458. //--------------------------------------------------------------  HandleOSEvent
  459.  
  460. // Handle switchin in and out events.  Standard event-handling stuff.
  461.  
  462. void HandleOSEvent (EventRecord *theEvent)
  463. {    
  464.     if (theEvent->message & 0x01000000)        // If suspend or resume event…
  465.     {
  466.         if (theEvent->message & 0x00000001)    // Specifically, if resume event…
  467.             switchedOut = FALSE;            // I keep thinking I should do more here.
  468.         else                                // Or if suspend event…
  469.             switchedOut = TRUE;                // What am I forgetting?
  470.     }
  471. }
  472.  
  473. //--------------------------------------------------------------  HandleHighLevelEvent
  474.  
  475. // Again, it's a fact I'm lazy.  AppleEvents are fairly easy to implement but…
  476. // a nightmare to try and explain.  Filling out the below function is left as…
  477. // and exercise to the reader.
  478.  
  479. void HandleHighLevelEvent (EventRecord *theEvent)
  480. {    
  481. //    theErr = AEProcessAppleEvent(theEvent);
  482. }
  483.  
  484. //--------------------------------------------------------------  HandleEvent
  485.  
  486. // Standard event stuff.  This is the culling function that calls all the above…
  487. // functions.  It looks for an event and if it detects one, it calls the appropriate…
  488. // function above to handle it.
  489.  
  490. void HandleEvent (void)
  491. {
  492.     EventRecord    theEvent;
  493.     long        sleep = 1L;
  494.     Boolean        itHappened;
  495.                                             // See if an event is queued up.
  496. #if GENERATINGPOWERPC
  497.         canPlay = TRUE;
  498. #endif
  499.  
  500.     itHappened = WaitNextEvent(everyEvent, &theEvent, sleep, 0L);
  501.     
  502.     if (itHappened)                            // Ah, an event.  I live for events!
  503.     {
  504.         switch (theEvent.what)                // And what kind of event be ya'?
  505.         {
  506.             case mouseDown:                    // Aiy!  Y' be a mouse click do ya'?
  507.             HandleMouseEvent(&theEvent);
  508.             break;
  509.             
  510.             case keyDown:                    // Key down, key held down events.
  511.             case autoKey:
  512.             HandleKeyEvent(&theEvent);
  513.             break;
  514.             
  515.             case updateEvt:                    // Something needs redrawing!
  516.             HandleUpdateEvent(&theEvent);
  517.             break;
  518.             
  519.             case osEvt:                        // Switching in and out events.
  520.             HandleOSEvent(&theEvent);
  521.             break;
  522.             
  523.             case kHighLevelEvent:            // Hmmmm.  A "what" event?
  524.             HandleHighLevelEvent(&theEvent);
  525.             break;
  526.         }
  527.     }
  528.     else if (openTheScores)                    // Check for "auto open" flag.
  529.     {                                        // If TRUE, set the flag back to…
  530.         openTheScores = FALSE;                // FALSE and open the high scores.
  531.         OpenHighScores();
  532.     }
  533. }
  534.  
  535. //--------------------------------------------------------------  DoAbout
  536.  
  537. // This handles the About dialog.  It brings up the About box in a…
  538. // simple centered window with no drag bar, close box or anything.
  539. // Leaving the dialog is handled with a simple mouse click.
  540.  
  541. void DoAbout (void)
  542. {
  543.     Rect        aboutRect;
  544.     WindowPtr    aboutWindow;
  545.     
  546.     SetRect(&aboutRect, 0, 0, 325, 318);        // Bring up centered window.
  547.     CenterRectInRect(&aboutRect, &qd.screenBits.bounds);
  548.     aboutWindow = GetNewCWindow(129, 0L, kPutInFront);
  549.     MoveWindow((GrafPtr)aboutWindow, aboutRect.left, aboutRect.top, TRUE);
  550.     ShowWindow((GrafPtr)aboutWindow);
  551.     SetPort((GrafPtr)aboutWindow);
  552.     LoadGraphic(kAboutPictID);                    // Draw About dialog graphic.
  553.     
  554.     do                                            // Make sure button not down…
  555.     {                                            // before proceeding.
  556.     }
  557.     while (Button());                            // Proceed.
  558.     do                                            // And now wait until the mouse…
  559.     {                                            // is pressed before closing the…
  560.     }                                            // window (ABout dialog).
  561.     while (!Button());
  562.     
  563.     FlushEvents(everyEvent, 0);                    // Flush the queue.
  564.     
  565.     if (aboutWindow != 0L)
  566.         DisposeWindow(aboutWindow);                // Close the About dialog.
  567. }
  568.  
  569. //--------------------------------------------------------------  DoGameSettings
  570.  
  571. // This one however is a good and proper dialog box.  It handles the meager…
  572. // preference settings for Glypha.  Nothing fancy here to report.  Just a…
  573. // straight-forward dialog calling routine.
  574.  
  575. void DoGameSettings (void)
  576. {
  577.     #define        kGameSettingsDialogID    133
  578.     DialogPtr    theDial;
  579.     long        newVolume;
  580.     short        i, item;
  581.     Boolean        leaving;
  582.     
  583.     CenterDialog(kGameSettingsDialogID);    // Center dialog, then call up.
  584.     theDial = GetNewDialog(kGameSettingsDialogID, 0L, kPutInFront);
  585.     SetPort((GrafPtr)theDial);
  586.     ShowWindow((GrafPtr)theDial);            // Make visible (after centering).
  587.     DrawDefaultButton(theDial);                // Draw border around Okay button.
  588.     FlushEvents(everyEvent, 0);
  589.                                             // Put in a default sound volume.
  590.     SetDialogNumToStr(theDial, 3, (long)thePrefs.wasVolume);
  591.     SelIText(theDial, 3, 0, 1024);            // Select it.
  592.     
  593.     leaving = FALSE;
  594.     
  595.     while (!leaving)
  596.     {
  597.         ModalDialog(0L, &item);                // Simple modal dialog filtering.
  598.         
  599.         if (item == 1)                        // Did user hit the Okay button?
  600.         {                                    // Well see if volume entered is legal.
  601.             GetDialogNumFromStr(theDial, 3, &newVolume);
  602.             if ((newVolume >= 0) && (newVolume <= 7))
  603.             {                                // If it is legal, we'll note it and quit.
  604.                 thePrefs.wasVolume = (short)newVolume;
  605.                 SetSoundVol((short)newVolume);
  606.                 leaving = TRUE;                // Bye.
  607.             }
  608.             else                            // Otherwise, the volume entered is wrong.
  609.             {                                // So we'll Beep, enter the last legal…
  610.                 SysBeep(1);                    // value and select the text again.
  611.                 SetDialogNumToStr(theDial, 3, (long)thePrefs.wasVolume);
  612.                 SelIText(theDial, 3, 0, 1024);
  613.             }
  614.         }
  615.         else if (item == 2)                    // Did the user hit the "Clear Scores"…
  616.         {                                    // button?
  617.             for (i = 0; i < 10; i++)        // Walk through and zero scores.
  618.             {
  619.                 PasStringCopy("\pNemo", thePrefs.highNames[i]);
  620.                 thePrefs.highScores[i] = 0L;
  621.                 thePrefs.highLevel[i] = 0;
  622.                 openTheScores = TRUE;        // Bring up scores when dialog quits.
  623.             }
  624.             DisableControl(theDial, 2);        // Gray out Clear Scores button.
  625.         }
  626.     }
  627.     
  628.     DisposDialog(theDial);                    // Clean up before going.
  629. }
  630.  
  631.